package atguigu.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author: DRevelation
 * @Date: 2021/3/16 14:09
 * NIO读文件
 */
public class NIOFileChannel02 {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\nio_01.txt");
        try (FileInputStream fileInputStream = new FileInputStream(file)) {
            FileChannel fileChannel = fileInputStream.getChannel();

            ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());
            fileChannel.read(byteBuffer);

            System.out.println(new String(byteBuffer.array()));
        }
    }
}
